package com.example.project.controller;

import com.example.project.dto.TcdmSecureHazardAssessmentRecycleDTO;
import com.example.project.entity.TcdmSecureHazardAssessmentRecycle;
import com.example.project.service.TcdmSecureHazardAssessmentRecycleService;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * (TcdmSecureHazardAssessmentRecycle)表控制层
 *
 * @author makejava
 * @since 2024-02-23 15:18:23
 */
@RestController
@CrossOrigin
@RequestMapping("tcdmSecureHazardAssessmentRecycle")
public class TcdmSecureHazardAssessmentRecycleController {
    /**
     * 服务对象
     */
    @Resource
    private TcdmSecureHazardAssessmentRecycleService tcdmSecureHazardAssessmentRecycleService;

    /**
     * 分页查询
     *
     * @param tcdmSecureHazardAssessmentRecycleDTO 筛选条件
     * @return 查询结果
     */
    @PostMapping("findPage")
    public ResponseEntity<Page<TcdmSecureHazardAssessmentRecycle>> queryByPage(@RequestBody TcdmSecureHazardAssessmentRecycleDTO tcdmSecureHazardAssessmentRecycleDTO) {
        com.example.project.entity.Page page=tcdmSecureHazardAssessmentRecycleDTO.getPage();
        return ResponseEntity.ok(this.tcdmSecureHazardAssessmentRecycleService.queryByPage(tcdmSecureHazardAssessmentRecycleDTO.getTcdmSecureHazardAssessmentRecycle(),PageRequest.of(page.getPage(), page.getSize())));
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */

    @GetMapping("{id}")
    public ResponseEntity<TcdmSecureHazardAssessmentRecycle> queryById(@PathVariable("id") Integer id) {
        return ResponseEntity.ok(this.tcdmSecureHazardAssessmentRecycleService.queryById(id));
    }

    /**
     * 查询所有数据
     *
     * @return 所有数据
     */
    @GetMapping("findAll")
    public List<TcdmSecureHazardAssessmentRecycle> findAll() {
        return tcdmSecureHazardAssessmentRecycleService.findList();
    }
    /**
     * 新增数据
     *
     * @param tcdmSecureHazardAssessmentRecycle 实体
     * @return 新增结果
     */

    @PostMapping("add")
    public ResponseEntity<TcdmSecureHazardAssessmentRecycle> add(@RequestBody TcdmSecureHazardAssessmentRecycle tcdmSecureHazardAssessmentRecycle) {
        return ResponseEntity.ok(this.tcdmSecureHazardAssessmentRecycleService.insert(tcdmSecureHazardAssessmentRecycle));
    }

    /**
     * 编辑数据
     *
     * @param tcdmSecureHazardAssessmentRecycle 实体
     * @return 编辑结果
     */

    @PutMapping("put")
    public ResponseEntity<TcdmSecureHazardAssessmentRecycle> edit(@RequestBody TcdmSecureHazardAssessmentRecycle tcdmSecureHazardAssessmentRecycle) {
        return ResponseEntity.ok(this.tcdmSecureHazardAssessmentRecycleService.update(tcdmSecureHazardAssessmentRecycle));
    }

    /**
     * 删除数据
     *
     * @param tcdmSecureHazardAssessmentRecycle 主键
     * @return 删除是否成功
     */

    @DeleteMapping("del")
    public ResponseEntity<Boolean> deleteById(@RequestBody TcdmSecureHazardAssessmentRecycle tcdmSecureHazardAssessmentRecycle) {
        return ResponseEntity.ok(this.tcdmSecureHazardAssessmentRecycleService.deleteById(tcdmSecureHazardAssessmentRecycle.getTshareId()));
    }

    @PostMapping("/recover")
    public ResponseEntity<Boolean> recover(@RequestBody TcdmSecureHazardAssessmentRecycle tcdmSecureHazardAssessmentRecycle){
        return ResponseEntity.ok(this.tcdmSecureHazardAssessmentRecycleService.recover(tcdmSecureHazardAssessmentRecycle.getTshareId()));
    }


    @DeleteMapping("deleteAll")
    public ResponseEntity<Boolean> deleteAll(){
        return ResponseEntity.ok(this.tcdmSecureHazardAssessmentRecycleService.deleteAll());
    }

}



